﻿using System.Linq.PageList;
using Dyao.Book.Application.Abstractions;
using Dyao.Book.Contract;
using Dyao.Book.Entity;
using Dyao.Book.Repository.Abstractions;
using Foundation.Uow;

namespace Dyao.Book.Application
{
    public class CommonApplication : BaseApplication, ICommonApplication
    {
        /// <inheritdoc cref="IBookMgrApplication.ModifyAsync"/>
        public async Task<IPageList<OperationLogResultDto>> GetOpLogPageListAsync(IPageFilter<OperationLogFilterDto> pageFilter, CancellationToken cancellationToken = default)
        {
            var opRepo = GetService<IOperationLogRepository>();
            var result = new PageList<OperationLogResultDto>();
            using var unitOfWork = UnitOfWorkManager.Begin(isReadDb: true);

            var pageList = await opRepo.GetPageListAsync(pageFilter, cancellationToken);

            if (pageList.Records == 0) return result;

            var resultList = ObjectMapper.Map<List<OperationLogEntity>, List<OperationLogResultDto>>(pageList.Data);

            return (PageList<OperationLogResultDto>)pageList.ToMap(resultList);
        }
    }
}
